package cn.ainit.bj.CIPApply;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.ainit.bj.CIPApply.entity.CIPApplyInfo;
import cn.ainit.common.ReturnObject;
import cn.ainit.sys.utils.UUID32;

@Controller
@RequestMapping("/cipApply")
public class CIPApplyController {
	
	private CIPApplyService cipApplyService;
	@Resource
	public void setCipApplyService(CIPApplyService cipApplyService) {
		this.cipApplyService = cipApplyService;
	}
	
	@RequestMapping("saOrUpCIP")
	@ResponseBody
	public ReturnObject saOrUpCIP(CIPApplyInfo cipApplyInfo,HttpServletRequest request) throws Exception{
		ReturnObject returnObject = new ReturnObject();
		try {
			boolean flag = false;
			String hid = "";  
			if (cipApplyInfo.getCipId() == null || cipApplyInfo.getCipId()=="" || cipApplyInfo.getCipId().equals("null") || cipApplyInfo.getCipId().equals("")) {
				hid =UUID32.newGuid();
				cipApplyInfo.setCipId(hid);
				flag = cipApplyService.saveCIPApply(cipApplyInfo);
				if (flag) {
					returnObject.setMsg("success");
					returnObject.setInfo(hid);
				}else{
					returnObject.setMsg("fail");
				}
			}else{
				flag = cipApplyService.updCIPApply(cipApplyInfo);
				if (flag) {
					returnObject.setMsg("upsuccess");
				}else {
					returnObject.setMsg("fail");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	    return returnObject ;
	}
}
